using ChikovMF.Application.Features.Projects.EditProject;
using Microsoft.EntityFrameworkCore;

namespace ChikovMF.Tests.Projects.Commands;

public class EditProjectTest : TestCommandBase
{
    [Fact]
    public async Task EditProjectTest_Success()
    {
        var handler = new EditProjectCommandHandler(_context);
        var command = new EditProjectCommand
        {
            Name = "editName",
            Content = "editContent",
            Description = "editDescription",
            ProjectId = new Guid("e6e7d3f0-b9b9-4f0b-a9b9-fe0b584bb9cd")
        };
        var oldProject = await _context.Projects.FirstOrDefaultAsync(project => project.ProjectId == command.ProjectId);
        

        var editProjectId = await handler.Handle(
            command,
            CancellationToken.None
        );


        Assert.NotNull(oldProject);
        var editProject = await _context.Projects.FirstOrDefaultAsync(project => project.ProjectId == command.ProjectId);
        Assert.NotNull(editProject);

        Assert.Equal(command.Name, editProject.Name);
        Assert.Equal(command.Content, editProject.Content);
        Assert.Equal(command.Description, editProject.Description);

        Assert.Equal(command.ProjectId, editProjectId);
        Assert.Equal(oldProject.ProjectId, editProject.ProjectId);
    }
}